package cn.xydpeng.springframework.test.postprocess;

import cn.xydpeng.springframework.beans.BeansException;
import cn.xydpeng.springframework.beans.MutablePropertyValues;
import cn.xydpeng.springframework.beans.PropertyValue;
import cn.xydpeng.springframework.beans.factory.config.BeanFactoryPostProcessor;
import cn.xydpeng.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import cn.xydpeng.springframework.beans.factory.support.RootBeanDefinition;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/19
 * @description:
 */
public class MyBeanFactoryPostProcesser implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        RootBeanDefinition mbd = (RootBeanDefinition) beanFactory.getBeanDefinition("userService");
        MutablePropertyValues propertyValues = (MutablePropertyValues) mbd.getPropertyValues();
        PropertyValue pv = new PropertyValue("company", "替换为--宇宙厂");
        propertyValues.addPropertyValue(pv);
    }
}
